package com.itheima.order.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.api.client.UserFeign;
import com.itheima.api.domain.User;
import com.itheima.order.domain.Order;
import com.itheima.order.mapper.OrderMapper;
import com.itheima.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order>
                                implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    //@Autowired
    //private RestTemplate restTemplate;

    @Autowired
    private UserFeign userFeign;

    public Order findOrderByUserId(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.selectById(orderId);
        //2. 远程调用用户微服务：根据id获取用户信息
        //String url ="http://user-service/user/"+order.getUserId();
        //User user = restTemplate.getForObject(url, User.class);
        User user = userFeign.findById(order.getUserId());
        //3. 封装用户信息到订单中
        order.setUser(user);
        // 4.返回
        return order;
    }
}
